package icu.qx.pbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import icu.qx.pbs.domain.PbsWorkCellType;
import icu.qx.pbs.service.IPbsWorkCellTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 生产单元类型Controller
 *
 * @author yong
 * @date 2024-06-18
 */
@RestController
@RequestMapping("/pbs/workCellType")
public class PbsWorkCellTypeController extends BaseController {
    @Autowired
    private IPbsWorkCellTypeService pbsWorkCellTypeService;

    /**
     * 查询生产单元类型列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PbsWorkCellType pbsWorkCellType) {
        startPage();
        List<PbsWorkCellType> list = pbsWorkCellTypeService.selectPbsWorkCellTypeList(pbsWorkCellType);
        return getDataTable(list);
    }

    /**
     * 查询所有生产单元类型列表
     */
    @GetMapping("/all")
    public AjaxResult all(PbsWorkCellType pbsWorkCellType) {
        List<PbsWorkCellType> list = pbsWorkCellTypeService.selectPbsWorkCellTypeList(pbsWorkCellType);
        return AjaxResult.success(list);
    }

    /**
     * 导出生产单元类型列表
     */
    @Log(title = "生产单元类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PbsWorkCellType pbsWorkCellType) {
        List<PbsWorkCellType> list = pbsWorkCellTypeService.selectPbsWorkCellTypeList(pbsWorkCellType);
        ExcelUtil<PbsWorkCellType> util = new ExcelUtil<PbsWorkCellType>(PbsWorkCellType.class);
        util.exportExcel(response, list, "生产单元类型数据");
    }

    /**
     * 获取生产单元类型详细信息
     */
    @GetMapping(value = "/{workCtCode}")
    public AjaxResult getInfo(@PathVariable("workCtCode") String workCtCode) {
        return success(pbsWorkCellTypeService.selectPbsWorkCellTypeByWorkCtCode(workCtCode));
    }

    /**
     * 新增生产单元类型
     */
    @Log(title = "生产单元类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PbsWorkCellType pbsWorkCellType) {
        return toAjax(pbsWorkCellTypeService.insertPbsWorkCellType(pbsWorkCellType));
    }

    /**
     * 修改生产单元类型
     */
    @Log(title = "生产单元类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PbsWorkCellType pbsWorkCellType) {
        return toAjax(pbsWorkCellTypeService.updatePbsWorkCellType(pbsWorkCellType));
    }

    /**
     * 删除生产单元类型
     */
    @Log(title = "生产单元类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{workCtCodes}")
    public AjaxResult remove(@PathVariable String[] workCtCodes) {
        return toAjax(pbsWorkCellTypeService.deletePbsWorkCellTypeByWorkCtCodes(workCtCodes));
    }
}
